package com.mikepenz.presenter.imp;

import android.content.Context;

import com.amap.api.maps2d.model.LatLng;
import com.android.volley.VolleyError;
import com.mikepenz.app.R;
import com.mikepenz.bean.ParkBean;
import com.mikepenz.interactor.MainFragInteractor;
import com.mikepenz.interactor.imp.MainFragInteractorImp;
import com.mikepenz.presenter.MainFragPresenter;
import com.mikepenz.presenter.listener.RequestListener;
import com.mikepenz.utils.CookicUntil;
import com.mikepenz.utils.SystemUtils;
import com.mikepenz.view.MainFragView;

import java.util.List;

/**
 * Created by Administrator on 2015/9/14.
 */
public class MainFragPresenterImp implements MainFragPresenter,RequestListener<List<ParkBean>> {
    private MainFragInteractor interactor;
    MainFragView view;
    Context c;

    int currentPage = 1;
    public MainFragPresenterImp (Context c){
        this(c,(MainFragView)c);
    }

    public MainFragPresenterImp(Context c,MainFragView view){
        this.c =c;
        this.view =view;
        interactor = new MainFragInteractorImp(c,this);
    }

    @Override
    public void getParking(LatLng latlng) {
        view.clearPostions();
        view.showLoad();
        String userId = CookicUntil.getUser().getUserId();
        if (!SystemUtils.checkUser(c)){
            view.showError(c.getString(R.string.user_not_login));
            return ;
        }
        interactor.getParking(latlng,userId,currentPage);
        currentPage ++;
    }

    @Override
    public void refreshParking(LatLng latlng) {
        view.clearPostions();
        currentPage = 1;
        String userId = CookicUntil.getUser().getUserId();
        interactor.getParking(latlng,userId,currentPage);
    }

    @Override
    public boolean checkCard() {

        return false;
    }

    @Override
    public boolean isLogin() {
        if (CookicUntil.getUser() == null)
            return false;
        else
            return true;
    }

    @Override
    public void Success(String tag, List<ParkBean> result) {
        view.dismissLoad();
        view.drawPostions(result);
    }

    @Override
    public void Error(String tag, String error) {
        view.showError(error);
    }

    @Override
    public void Exception(String tag, VolleyError error) {
        view.showError(c.getResources().getString(R.string.system_error));
    }
}
